from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-06 14:02:46.281353
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 06, Mar, 2022
Time: 14:02:53
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4028
Nobs: 587.000 HQIC: -48.8122
Log likelihood: 6996.83 FPE: 4.87128e-22
AIC: -49.0735 Det(Omega_mle): 4.18425e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351156 0.067680 5.188 0.000
L1.Burgenland 0.108300 0.041083 2.636 0.008
L1.Kärnten -0.110641 0.021454 -5.157 0.000
L1.Niederösterreich 0.191148 0.085848 2.227 0.026
L1.Oberösterreich 0.122652 0.084770 1.447 0.148
L1.Salzburg 0.257759 0.043539 5.920 0.000
L1.Steiermark 0.036949 0.057496 0.643 0.520
L1.Tirol 0.101937 0.046424 2.196 0.028
L1.Vorarlberg -0.068448 0.040932 -1.672 0.094
L1.Wien 0.016420 0.075385 0.218 0.828
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051872 0.145647 0.356 0.722
L1.Burgenland -0.037686 0.088411 -0.426 0.670
L1.Kärnten 0.041809 0.046168 0.906 0.365
L1.Niederösterreich -0.204340 0.184745 -1.106 0.269
L1.Oberösterreich 0.458197 0.182424 2.512 0.012
L1.Salzburg 0.282474 0.093697 3.015 0.003
L1.Steiermark 0.113599 0.123731 0.918 0.359
L1.Tirol 0.304578 0.099904 3.049 0.002
L1.Vorarlberg 0.026133 0.088087 0.297 0.767
L1.Wien -0.027505 0.162228 -0.170 0.865
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200424 0.034528 5.805 0.000
L1.Burgenland 0.088483 0.020959 4.222 0.000
L1.Kärnten -0.007275 0.010945 -0.665 0.506
L1.Niederösterreich 0.239902 0.043797 5.478 0.000
L1.Oberösterreich 0.161276 0.043247 3.729 0.000
L1.Salzburg 0.040209 0.022212 1.810 0.070
L1.Steiermark 0.025776 0.029333 0.879 0.380
L1.Tirol 0.081964 0.023684 3.461 0.001
L1.Vorarlberg 0.053674 0.020882 2.570 0.010
L1.Wien 0.117668 0.038459 3.060 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.119849 0.034523 3.472 0.001
L1.Burgenland 0.042134 0.020956 2.011 0.044
L1.Kärnten -0.013115 0.010943 -1.198 0.231
L1.Niederösterreich 0.170682 0.043790 3.898 0.000
L1.Oberösterreich 0.338058 0.043240 7.818 0.000
L1.Salzburg 0.100018 0.022209 4.503 0.000
L1.Steiermark 0.110045 0.029328 3.752 0.000
L1.Tirol 0.089824 0.023680 3.793 0.000
L1.Vorarlberg 0.060442 0.020879 2.895 0.004
L1.Wien -0.018267 0.038453 -0.475 0.635
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124905 0.064945 1.923 0.054
L1.Burgenland -0.044743 0.039423 -1.135 0.256
L1.Kärnten -0.045384 0.020587 -2.205 0.027
L1.Niederösterreich 0.135307 0.082379 1.642 0.100
L1.Oberösterreich 0.162099 0.081344 1.993 0.046
L1.Salzburg 0.284907 0.041780 6.819 0.000
L1.Steiermark 0.058221 0.055172 1.055 0.291
L1.Tirol 0.157417 0.044548 3.534 0.000
L1.Vorarlberg 0.096934 0.039278 2.468 0.014
L1.Wien 0.073474 0.072338 1.016 0.310
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.079305 0.050635 1.566 0.117
L1.Burgenland 0.024838 0.030736 0.808 0.419
L1.Kärnten 0.053265 0.016051 3.319 0.001
L1.Niederösterreich 0.188765 0.064227 2.939 0.003
L1.Oberösterreich 0.332910 0.063421 5.249 0.000
L1.Salzburg 0.033955 0.032574 1.042 0.297
L1.Steiermark 0.006779 0.043016 0.158 0.875
L1.Tirol 0.119295 0.034732 3.435 0.001
L1.Vorarlberg 0.065323 0.030624 2.133 0.033
L1.Wien 0.097496 0.056399 1.729 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171332 0.061126 2.803 0.005
L1.Burgenland 0.004821 0.037105 0.130 0.897
L1.Kärnten -0.065936 0.019376 -3.403 0.001
L1.Niederösterreich -0.107046 0.077535 -1.381 0.167
L1.Oberösterreich 0.209266 0.076561 2.733 0.006
L1.Salzburg 0.054299 0.039323 1.381 0.167
L1.Steiermark 0.247135 0.051928 4.759 0.000
L1.Tirol 0.499583 0.041928 11.915 0.000
L1.Vorarlberg 0.064154 0.036969 1.735 0.083
L1.Wien -0.074410 0.068085 -1.093 0.274
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161700 0.067802 2.385 0.017
L1.Burgenland -0.002555 0.041157 -0.062 0.950
L1.Kärnten 0.062884 0.021492 2.926 0.003
L1.Niederösterreich 0.165820 0.086003 1.928 0.054
L1.Oberösterreich -0.054821 0.084923 -0.646 0.519
L1.Salzburg 0.208722 0.043618 4.785 0.000
L1.Steiermark 0.138148 0.057600 2.398 0.016
L1.Tirol 0.055762 0.046508 1.199 0.231
L1.Vorarlberg 0.146696 0.041007 3.577 0.000
L1.Wien 0.120757 0.075521 1.599 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392275 0.039818 9.852 0.000
L1.Burgenland -0.004131 0.024170 -0.171 0.864
L1.Kärnten -0.021129 0.012622 -1.674 0.094
L1.Niederösterreich 0.200212 0.050507 3.964 0.000
L1.Oberösterreich 0.230478 0.049873 4.621 0.000
L1.Salzburg 0.037115 0.025616 1.449 0.147
L1.Steiermark -0.016717 0.033827 -0.494 0.621
L1.Tirol 0.090428 0.027312 3.311 0.001
L1.Vorarlberg 0.050752 0.024082 2.107 0.035
L1.Wien 0.043503 0.044351 0.981 0.327
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036612 0.102922 0.167886 0.138077 0.095283 0.080496 0.032119 0.209273
Kärnten 0.036612 1.000000 -0.027781 0.131598 0.048276 0.084870 0.443613 -0.067198 0.089308
Niederösterreich 0.102922 -0.027781 1.000000 0.311090 0.118337 0.270170 0.065779 0.151540 0.288168
Oberösterreich 0.167886 0.131598 0.311090 1.000000 0.212427 0.294353 0.166665 0.135667 0.235253
Salzburg 0.138077 0.048276 0.118337 0.212427 1.000000 0.122244 0.090911 0.104371 0.123083
Steiermark 0.095283 0.084870 0.270170 0.294353 0.122244 1.000000 0.134102 0.106097 0.033240
Tirol 0.080496 0.443613 0.065779 0.166665 0.090911 0.134102 1.000000 0.063203 0.150805
Vorarlberg 0.032119 -0.067198 0.151540 0.135667 0.104371 0.106097 0.063203 1.000000 -0.005237
Wien 0.209273 0.089308 0.288168 0.235253 0.123083 0.033240 0.150805 -0.005237 1.000000